home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
676-700
/
681
/
term
/
source.lha
/
LocaleSupport.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-09
|
6KB
|
355 lines
/*
** $Id: LocaleSupport.c,v 1.6 92/05/01 12:52:31 olsen Sta Locker: olsen $
** $Revision: 1.6 $
** $Date: 92/05/01 12:52:31 $
**
** Localization support routines
**
** Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
extern struct
{
LONG as_ID;
STRPTR as_Str;
} AppStrings[];
extern LONG NumAppStrings;
struct LocaleBase *LocaleBase;
struct Catalog *Catalog;
struct Locale *Locale;
/* LocaleOpen(STRPTR CatalogName,STRPTR BuiltIn):
*
* Open string translation tables.
*/
VOID __regargs
LocaleOpen(STRPTR CatalogName,STRPTR BuiltIn,LONG Version)
{
#ifdef LIBRARIES_LOCALE_H
if(LocaleBase = (struct LocaleBase *)OpenLibrary("locale.library",38))
{
if(LocaleBase -> lb_SysPatches)
{
strcpy(ConvNumber,"%lD");
strcpy(ConvNumber10,"%10lD");
Catalog = OpenCatalog(NULL,CatalogName,
OC_BuiltInLanguage, BuiltIn,
OC_BuiltInCodeSet, 0,
/* OC_Version, Version,*/
TAG_DONE);
Locale = OpenLocale(NULL);
}
else
{
strcpy(ConvNumber,"%ld");
strcpy(ConvNumber10,"%10ld");
CloseLibrary(LocaleBase);
LocaleBase = NULL;
}
}
else
{
strcpy(ConvNumber,"%ld");
strcpy(ConvNumber10,"%10ld");
}
#else
strcpy(ConvNumber,"%ld");
strcpy(ConvNumber10,"%10ld");
#endif /* LIBRARIES_LOCALE_H */
}
/* LocaleClose():
*
* Close the translation tables.
*/
VOID
LocaleClose()
{
if(Locale)
CloseLocale(Locale);
if(Catalog)
CloseCatalog(Catalog);
if(LocaleBase)
CloseLibrary(LocaleBase);
}
/* LanguageCheck():
*
* Checks to see if the currently selected language
* is english.
*/
VOID
LanguageCheck()
{
#ifdef LIBRARIES_LOCALE_H
if(Locale && Catalog)
{
if(Locale -> loc_LanguageName)
{
if(!Stricmp(Locale -> loc_LanguageName,"english.language"))
English = TRUE;
else
English = FALSE;
}
else
English = FALSE;
}
else
English = TRUE;
#else
English = TRUE;
#endif /* LIBRARIES_LOCALE_H */
}
/* GadToolsStrlen(STRPTR *String):
*
* Custom version of strlen, useful for gadtools object titles
* with embedded underscore characters.
*/
WORD __regargs
GadToolsStrlen(STRPTR String)
{
WORD Len = 0;
while(*String)
{
if(*String++ != '_')
Len++;
}
return(Len);
}
/* GadToolsLongestString(WORD From,WORD To):
*
* Determines the longest string used by a gadtools
* control panel.
*/
WORD __regargs
GadToolsLongestString(WORD From,WORD To)
{
STRPTR Text;
WORD MaxLen = 0,
Len,i;
for(i = From ; i <= To ; i++)
{
if(Text = LocaleString(i))
{
if((Len = GadToolsStrlen(Text)) > MaxLen)
MaxLen = Len;
}
}
return(MaxLen);
}
/* SmallCurrency():
*
* Support function for the rates control panel, returns a formatted
* string to contain a string like "cents/unit".
*/
STRPTR __regargs
SmallCurrency()
{
STATIC UBYTE Buffer[30];
#ifdef LIBRARIES_LOCALE_H
if(Locale)
SPrintf(Buffer,LocaleString(MSG_RATEPANEL_PAY_PER_UNIT_GAD),Locale -> loc_MonSmallCS);
else
SPrintf(Buffer,LocaleString(MSG_RATEPANEL_PAY_PER_UNIT_GAD),"Pay");
#else
SPrintf(Buffer,LocaleString(MSG_RATEPANEL_PAY_PER_UNIT_GAD),"Pay");
#endif /* LIBRARIES_LOCALE_H */
return(Buffer);
}
/* CreateSum(LONG Quantity):
*
* Create a string containing a monetary quantity formatted
* according to the current locale rules.
*/
STRPTR __regargs
CreateSum(LONG Quantity,BYTE UseCurrency)
{
STATIC UBYTE Buffer[20];
#ifdef LIBRARIES_LOCALE_H
if(Locale)
{
if(Locale -> loc_MonFracDigits < 6)
{
STATIC LONG Power[] = { 1, 10, 100, 1000, 10000, 100000 };
UBYTE Buffer2[20];
LONG Int,
Frac;
if(UseCurrency)
{
strcpy(Buffer2,"%s %lD%s%");
SPrintf(&Buffer2[9],"%02ld",Locale -> loc_MonFracDigits);
strcat(Buffer2,"lD");
Int = Quantity / Power[Locale -> loc_MonFracDigits];
Frac = Quantity % Power[Locale -> loc_MonFracDigits];
SPrintf(Buffer,Buffer2,Locale -> loc_MonCS,Int,Locale -> loc_MonDecimalPoint,Frac);
}
else
{
STATIC UBYTE Buffer1[20];
strcpy(Buffer2,"%lD%s%");
SPrintf(&Buffer2[6],"%02ld",Locale -> loc_MonFracDigits);
strcat(Buffer2,"lD");
Int = Quantity / Power[Locale -> loc_MonFracDigits];
Frac = Quantity % Power[Locale -> loc_MonFracDigits];
SPrintf(Buffer1,Buffer2,Int,Locale -> loc_MonDecimalPoint,Frac);
return(Buffer1);
}
}
else
SPrintf(Buffer,"%lD.%02ld",Quantity / 100,Quantity % 100);
}
else
SPrintf(Buffer,"%ld.%02ld",Quantity / 100,Quantity % 100);
#else
SPrintf(Buffer,"%ld.%02ld",Quantity / 100,Quantity % 100);
#endif /* LIBRARIES_LOCALE_H */
return(Buffer);
}
/* LocalizeString(STRPTR *Strings,WORD From,WORD To):
*
* Localize an array of strings.
*/
VOID __regargs
LocalizeString(STRPTR *Strings,WORD From,WORD To)
{
WORD i,j;
for(i = From, j = 0 ; i <= To ; i++)
{
if(!Strings[j])
Strings[j++] = LocaleString(i);
}
}
/* LocalizeMenu(struct NewMenu *Menu,WORD From):
*
* Localize a NewMenu definition.
*/
VOID __regargs
LocalizeMenu(struct NewMenu *Menu,WORD From)
{
STRPTR Label,Shortcut;
while(Menu -> nm_Type != NM_END)
{
Shortcut = LocaleString(From);
if(Shortcut[0] && !Shortcut[1])
Label = Shortcut + 2;
else
{
Label = Shortcut;
Shortcut = NULL;
}
switch(Menu -> nm_Type)
{
case NM_TITLE: Menu -> nm_Label = Label;
From++;
break;
case NM_ITEM:
case NM_SUB: if(Menu -> nm_Label != NM_BARLABEL)
{
Menu -> nm_Label = Label;
Menu -> nm_CommKey = Shortcut;
From++;
}
break;
}
Menu++;
}
}
/* LocaleString(LONG ID):
*
* Obtain a string from the translation pool.
*/
STRPTR __regargs
LocaleString(LONG ID)
{
STRPTR Builtin;
if(AppStrings[ID] . as_ID == ID)
Builtin = AppStrings[ID] . as_Str;
else
{
WORD i;
Builtin = NULL;
for(i = 0 ; i < NumAppStrings ; i++)
{
if(AppStrings[i] . as_ID == ID)
{
Builtin = AppStrings[i] . as_Str;
break;
}
}
}
if(Catalog)
{
STRPTR String = GetCatalogStr(Catalog,ID,Builtin);
if(String[0])
return(String);
else
return(Builtin);
}
else
return(Builtin);
}